package com.dg11185.nearshop.activity.user.order;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.nearshop.R;

public class ActivityRecordActivity extends FragmentActivity implements OnClickListener {
    private ViewPager mPager;// 页卡内容

    private TextView t1, t2;// 页卡头标

    private FragmentAdapter pageAdapter;

    private Fragment f1, f2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);

        this.findViewById(R.id.text1).setOnClickListener(this);
        this.findViewById(R.id.text2).setOnClickListener(this);
        f1 = new Record1();
        f2 = new Record2();
        InitViewPager();

    }

    @Override
    protected void onResume() {
        super.onResume();

//        Bundle bundle = getIntent().getExtras();
//        int currentindex = bundle.getInt("pageindex");
//        if (currentindex == 1) {
//            mPager.setCurrentItem(currentindex);
//        }
    }

    /**
     * 初始化ViewPager
     */
    private void InitViewPager() {
        mPager = (ViewPager) findViewById(R.id.vPager);

        pageAdapter = new FragmentAdapter(getSupportFragmentManager());
        mPager.setAdapter(pageAdapter);
        mPager.setCurrentItem(0);
        mPager.setOnPageChangeListener(new MyOnPageChangeListener());
    }

    public class FragmentAdapter extends FragmentPagerAdapter {

        public FragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int arg0) {
            Fragment fragment = null;

            switch (arg0) {
            case 0:
                fragment = f1;
                break;
            case 1:
                fragment = f2;
                break;
            default:
                break;
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return 2;
        }
    }

    /**
     * 页卡切换监听
     */
    public class MyOnPageChangeListener implements OnPageChangeListener {

        public void onPageSelected(int arg0) {

        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        public void onPageScrollStateChanged(int arg0) {
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.text1:

            break;
        case R.id.text2:
            
            break;
        default:
            break;
        }
    }

}
